package cn.kgc.mes.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.kgc.mes.common.annotation.Log;
import cn.kgc.mes.common.core.controller.BaseController;
import cn.kgc.mes.common.core.domain.AjaxResult;
import cn.kgc.mes.common.enums.BusinessType;
import cn.kgc.mes.domain.MachineRepair;
import cn.kgc.mes.service.IMachineRepairService;
import cn.kgc.mes.common.utils.poi.ExcelUtil;
import cn.kgc.mes.common.core.page.TableDataInfo;

/**
 * 设备维修单Controller
 * 
 * @author lhd
 * @date 2025-09-11
 */
@RestController
@RequestMapping("/ls1/machineRepair")
public class MachineRepairController extends BaseController
{
    @Autowired
    private IMachineRepairService machineRepairService;

    /**
     * 查询设备维修单列表
     */
//    @PreAuthorize("@ss.hasPermi('ls1:machineRepair:list')")
    @GetMapping("/list")
    public TableDataInfo list(MachineRepair machineRepair)
    {
        startPage();
        List<MachineRepair> list = machineRepairService.selectMachineRepairList(machineRepair);
        return getDataTable(list);
    }

    /**
     * 导出设备维修单列表
     */
//    @PreAuthorize("@ss.hasPermi('ls1:machineRepair:export')")
    @Log(title = "设备维修单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MachineRepair machineRepair)
    {
        List<MachineRepair> list = machineRepairService.selectMachineRepairList(machineRepair);
        ExcelUtil<MachineRepair> util = new ExcelUtil<MachineRepair>(MachineRepair.class);
        util.exportExcel(response, list, "设备维修单数据");
    }

    /**
     * 获取设备维修单详细信息
     */
//    @PreAuthorize("@ss.hasPermi('ls1:machineRepair:query')")
    @GetMapping(value = "/{repairId}")
    public AjaxResult getInfo(@PathVariable("repairId") Long repairId)
    {
        return success(machineRepairService.selectMachineRepairByRepairId(repairId));
    }

    /**
     * 新增设备维修单
     */
//    @PreAuthorize("@ss.hasPermi('ls1:machineRepair:add')")
    @Log(title = "设备维修单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MachineRepair machineRepair)
    {
        return toAjax(machineRepairService.insertMachineRepair(machineRepair));
    }

    /**
     * 修改设备维修单
     */
//    @PreAuthorize("@ss.hasPermi('ls1:machineRepair:edit')")
    @Log(title = "设备维修单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MachineRepair machineRepair)
    {
        return toAjax(machineRepairService.updateMachineRepair(machineRepair));
    }

    /**
     * 删除设备维修单
     */
//    @PreAuthorize("@ss.hasPermi('ls1:machineRepair:remove')")
    @Log(title = "设备维修单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{repairIds}")
    public AjaxResult remove(@PathVariable Long[] repairIds)
    {
        return toAjax(machineRepairService.deleteMachineRepairByRepairIds(repairIds));
    }
}
